<template>
  <div class="g-dialog-panel confirm">
    <div class="g-dialog-title">
      <span>You will receive</span>
      <div class="g-clickable close" @click="$emit('close')">
        <i class="iconfont icon-close"></i>
      </div>
    </div>
    <div class="liquidity add" v-if="type === 'add'">
      <div class="liquidity__token">
        <span>{{ amountLP }}</span>
        <img :src="token0.icon" />
        <img :src="token1.icon" />
      </div>
      <div class="liquidity__name">
        <span>{{ token0.symbol }}/{{ token1.symbol }} Pool Tokens</span>
      </div>
      <div class="liquidity__tips">
        <span
          >Output is estimated. If the price changes by more than 0.8% you
          transaction will revert.</span
        >
      </div>
      <div class="liquidity__info">
        <div class="item">
          <span>{{ token0.symbol }} Deposited</span>
          <div>
            <span>{{ amountA }}</span>
            <img :src="token0.icon" />
          </div>
        </div>
        <div class="item">
          <span>{{ token1.symbol }} Deposited</span>
          <div>
            <span>{{ amountB }}</span>
            <img :src="token1.icon" />
          </div>
        </div>
        <div class="item">
          <span>Rates</span>
          <span
            >1 {{ token0.symbol }} = {{ token0Price }} {{ token1.symbol }}</span
          >
        </div>
        <div class="item">
          <span>Rates</span>
          <span
            >1 {{ token1.symbol }} = {{ token1Price }} {{ token0.symbol }}</span
          >
        </div>
        <div class="item">
          <span>Share of Pool</span>
          <span>{{ percent }}%</span>
        </div>
        <ButtonBase
          label="Confirm Supply"
          class="confirm"
          @click="$emit('confirm')"
        />
      </div>
    </div>
    <div class="liquidity remove" v-else>
      <div class="liquidity__token">
        <span>{{ amountA }}</span>
        <img :src="token0.icon" />
      </div>
      <div class="liquidity__plus">
        <i class="iconfont icon-add"></i>
      </div>
      <div class="liquidity__token">
        <span>{{ amountB }}</span>
        <img :src="token1.icon" />
      </div>
      <div class="liquidity__tips">
        <span
          >Output is estimated. If the price changes by more than 0.8% you
          transaction will revert.</span
        >
      </div>
      <div class="liquidity__info">
        <div class="item">
          <span>LP {{ token0.symbol }}/{{ token1.symbol }} Burned</span>
          <div>
            <img :src="token0.icon" />
            <img :src="token1.icon" />
            <span>{{ amountLP }}</span>
          </div>
        </div>
        <div class="item">
          <span>Price</span>
          <span
            >1 {{ token0.symbol }} = {{ token0Price }} {{ token1.symbol }}</span
          >
        </div>
        <div class="item">
          <span></span>
          <span
            >1 {{ token1.symbol }} = {{ token1Price }} {{ token0.symbol }}</span
          >
        </div>
        <ButtonBase label="Confirm" class="confirm" @click="$emit('confirm')" />
      </div>
    </div>
  </div>
</template>

<script>
import ButtonBase from "@/components/common/ButtonBase";
export default {
  components: {
    ButtonBase,
  },
  props: {
    type: {
      type: String,
      default: "",
    },
    pair: {
      type: Object,
      default() {
        return {};
      },
    },
    amountA: {
      type: [Number, String],
      default: 0,
    },
    amountB: {
      type: [Number, String],
      default: 0,
    },
    amountLP: {
      type: [Number, String],
      default: 0,
    },
    percent: {
      type: [Number, String],
      default: 0,
    },
  },
  computed: {
    token0() {
      return (this.pair && this.pair.token0) || {};
    },
    token1() {
      return (this.pair && this.pair.token1) || {};
    },
    token0Price() {
      return (this.pair && this.pair._token0Price) || {};
    },
    token1Price() {
      return (this.pair && this.pair._token1Price) || {};
    },
    totalSupply() {
      return (this.pair && this.pair.totalSupply) || 0;
    },
    userLiquidity() {
      return (this.pair && this.pair.userLiquidity) || 0;
    },
    userLiquidityPercent() {
      return Math.ceil((this.userLiquidity / this.totalSupply) * 10000) / 100;
    },
  },
};
</script>

<style lang="scss" scoped>
.g-dialog-title {
  span {
    font-family: "Roboto Medium";
  }
}
.liquidity {
  &.add {
    .liquidity__token {
      height: 30px;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      margin: 40px 0 25px;
      span {
        font-size: 16px;
        font-family: "Roboto Bold";
        color: var(--color);
        margin-right: 10px;
      }
      img {
        width: 30px;
        border-radius: 15px;
      }
    }
    .liquidity__info {
      .item {
        img {
          margin-right: 0;
          margin-left: 5px;
        }
      }
    }
  }
  &.remove {
    padding-top: 30px;
    .liquidity__token {
      height: 30px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin: 10px 0;
      span {
        font-size: 20px;
        font-family: "Roboto Medium";
        color: var(--color);
      }
      img {
        width: 30px;
        border-radius: 15px;
      }
    }
    .liquidity__tips {
      margin-top: 30px;
    }
  }
  &__plus {
    padding: 5px 0;
    i {
      font-size: 24px;
      font-weight: 500;
      color: var(--color-content);
    }
  }
  &__name {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: 25px;

    span {
      font-size: 20px;
      font-family: "Roboto Bold";
      color: var(--color);
    }
  }
  &__tips {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: 25px;

    span {
      font-size: 12px;
      line-height: 1.5;
      font-family: "Roboto Regular";
      font-style: italic;
      color: var(--color-content);
    }
  }
  &__info {
    margin: 0 -24px -24px;
    padding: 18px 20px;
    background-color: rgba(255, 255, 255, 0.03);
    border-radius: 6px 6px 15px 15px;

    .item {
      margin: 0 8px;
      height: 36px;
      display: flex;
      align-items: center;
      justify-content: space-between;

      div {
        display: flex;
        align-items: center;
        justify-content: flex-end;
      }

      span {
        font-size: 14px;
        font-family: "Roboto Medium";
        color: var(--color);
      }

      img {
        width: 24px;
        border-radius: 12px;
        margin-right: 5px;
      }
    }
    .confirm {
      margin-top: 20px;
      background-image: linear-gradient(#1a1b20, #1a1b20),
        linear-gradient(to right, #94f2ff, #ffa8dc);
    }
  }
}
</style>
